package com.itheima.myscoket.test7;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        //接收客户端的文件
        ServerSocket ss = new ServerSocket(10000);
        Socket accept = ss.accept();
        //在创造输入流
        InputStream is = accept.getInputStream();
        //再将客户端发送过来的文件进行读取,再把网络中的流读取的数据
        BufferedInputStream bis = new BufferedInputStream(is);
        //这是本地流,把数据写到文件中的
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day16_网络编程\\Server\\1.jpg"));
        //现在开始读写
        int b;
        while ((b = bis.read()) != -1) {
            //再写
            bos.write(b);
        }

        //结束之后给客户端一个反馈,上传成功,上传到程序中的流accept.getOutputStream(),字节通过转换流变成字符输出到客户端
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("上传完成!");
        bw.newLine();
        bw.flush();
        bw.close();
        bos.close();
        bis.close();
        ss.close();

    }
}
